//for(var i = 0; i < 10; i++) {
//    
//    (function() {
//        console.log(i);
//    })();
//}

(function(){
    
        
    var lrchecker = {

        checkField: function(event) {
            var value = $(this).val();
            if(value=='') 
            {
                $(this).removeClass('field-error')  
                return;
            }
         
            var reg = /[a-zA-Z0-9]{6,20}/i;

            if(!reg.test(value))
            {
                $(this).addClass('field-error');     
            }
            else
            {
                $(this).removeClass('field-error')  
            }
        },
    
        test2: function()
        {
            alert("lol");
            return this;
        },
        getXmlHttp: function(){
            var xmlhttp;
            
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    xmlhttp = false;
                }
            }
            if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest();
            }
            return xmlhttp;
        },
        checkLoginInBase: function() {
            $('#center_container > #messages').remove();
            var value = $(this).val();      
            if(value=='') return;
            //отображаем progressbar
            var progress = $(this).after($('<img>', {src: 'templates/standart/img/pb.gif', class: 'progress-bar', id: 'progress'}));
            //autocomplete control, autosuggest textbox
            $.ajax({  
                type: 'POST',  
                url: 'LR/ajax/checklogin',  
                data: 'user_login='+$(this).val(),  
                success: function(json){
                    var answer_obj = $.parseJSON(json); 
                    var messageblock = $('<div>', {
                        id: 'messages',
                        class: 'alert alert-error'
                    }).prepend($('<ul>'));
                    for(var i = 0; i < answer_obj.messages.length; i++)
                    {
                         messageblock.children('ul').prepend($('<li>',{text: answer_obj.messages[i]}));
                    }
                    
                    
                    $('#center_container').prepend(messageblock);
                    messageblock.hide().slideDown('fast');

                    $('#progress').remove();
                }  
            });  
        }
    }    
    
    $(document).ready(function() {
        $('input[name=login]').bind('change', lrchecker.checkLoginInBase);
    });
    
})();







